#include "floodfill_mdf.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
int main(int /*argc*/, char * /*argv*/[])
{
	using namespace std;
	srand(time(0));

	//0,1联通矩阵，0是障碍，1是可通区域
	vector<vector<char> > v_mat;
	const int rows = 24, cols = 39;
	for (int i = 0; i < rows; ++i)
	{
		vector<char> v_row;
		v_row.resize(cols, 1);
		if (rand() % 100 < 30)
			for (int j = 0; j < 4; ++j)
				v_row[rand() % cols] = 0;
		v_mat.push_back(std::move(v_row));
	}
	//起点、终点
	const int startx = rand() % cols, starty = rand() % rows;
	const int endx = (startx + rand() % (cols - 3) + 2) % cols,
			  endy = (starty + rand() % (rows - 3) + 2) % rows;

	v_mat[starty][startx] = 1;
	v_mat[endy][endx] = 1;

	std::vector<int> cx, cy, idx;
	//找路径
	if (min_distance_find(v_mat, startx, starty, endx, endy, &cx, &cy, &idx) > 0)
	{
		vector<vector<char> > disp = v_mat;
		const int psz = cx.size();
		for (int i = 0; i < psz; ++i)
		{
			assert(cx[i] >= 0 && cx[i] < cols);
			assert(cy[i] >= 0 && cy[i] < rows);
			disp[cy[i]][cx[i]] = -1;
		}
		const int impsz = idx.size();
		for (int i = 0; i < impsz; ++i)
		{
			const int impx = cx[idx[i]];
			const int impy = cy[idx[i]];
			assert(impx >= 0 && impx < cols);
			assert(impy >= 0 && impy < rows);
			disp[impy][impx] = i + 2;
		}
		disp[starty][startx] = -2;
		disp[endy][endx] = -3;
		for (int i = 0; i < rows; ++i)
		{
			for (int j = 0; j < cols; ++j)
			{
				if (disp[i][j] == 1)
					cout << "  ";
				else if (disp[i][j] >= 2)
					printf("%02X", (unsigned int) (disp[i][j] - 2) % 0xFFu);
				else if (disp[i][j] == -1)
					cout << "[]";
				else if (disp[i][j] == -2)
					cout << "SS";
				else if (disp[i][j] == -3)
					cout << "EE";
				else
					cout << "XX";
			}
			cout << endl;
		}
	}
	else
	{
		cout << "不可达!";
	}

	return 0;
}
